import { HTTP } from '../utils/http';

class IndexModel extends HTTP {
  getNewsList(field, showCount) {
    // promise把pageData抛出去
    return new Promise((resolve, reject) => {
      this.ajax({
        url: 'Juhe/getNewsList',
        type: 'POST',
        dataType: 'JSON',
        data: {
          field
        },
        success(data) {
          const listDatas = data.result.data,
            len = listDatas.length;

          let pageData = [],
            index = 0;

          while (index < len) {
            // slice返回新数组
            pageData.push(listDatas.slice(index, index += showCount));
          }

          resolve(pageData);
        },

        error() {
          resolve(404);
        }
      });
    });
  }
}

export { IndexModel };
